import DZModelPage from '@/model/DZModelPage';
import nyNetwork from "@/api/nyBaseNetwork";
import DZModelStaff from "../model/DZModelStaff";

class DZServiceStaff {

    company = "";

    companyName = "";

    str_key = "";

    list_staff: Array<DZModelStaff> = [];

    list_department_by_company = [];

    m_page = new DZModelPage(10);

    net_list_staff() {
        var list_data = [];
        var param = { ...this.m_page, company: this.company, key: this.str_key }
        nyNetwork.net("员工列表", param, data => {
            this.m_page.total = data.total;
            var dataList = data.list;
            for (const item of dataList) {
                var staff = new DZModelStaff();
                staff.id = item.iId ?? "";
                staff.department = item.sDepartmentName ?? "";
                staff.phone = item.sPhone ?? "";
                staff.job = item.sJobNum ?? "";
                staff.name = item.sName ?? "";
                staff.city = item.sCity ?? "";
                staff.status = item.iStatus ?? 0;
                list_data.push(staff);
            }
            this.list_staff = list_data;
        })
    }

    net_staff_company_department(company,department) {
        var list_data = [];
        nyNetwork.net("公司员工列表", {companyId:company,department:department} , data => {
            for (const item of data) {
                var staff = new DZModelStaff();
                staff.id = item.iId ?? "";
                staff.department = item.sDepartmentName ?? "";
                staff.phone = item.sPhone ?? "";
                staff.job = item.sJobNum ?? "";
                staff.name = item.sName ?? "";
                staff.city = item.sCity ?? "";
                staff.status = item.iStatus ?? 0;
                staff.company = item.sCompany ?? "";
                list_data.push(staff);
            }
            this.list_staff = list_data;
        })
    }
    net_staff_by_ids(idList) {
        var list_data = [];
        nyNetwork.net("查询员工信息", [...idList] , data => {
            for (const item of data) {
                var staff = new DZModelStaff();
                staff.id = item.iId ?? "";
                staff.department = item.sDepartmentName ?? "";
                staff.name = item.sName ?? "";
                staff.city = item.sCity ?? "";
                staff.company = item.sCompany ?? "";
                list_data.push(staff);
            }
            this.list_staff = list_data;
        })
    }
    net_department_all_company(company) {
        nyNetwork.net("公司部门列表", [...company] , data => {
            this.list_department_by_company = data;
        })
    }

    net_add_staff(data, success: () => void) {
        var params = {
            company: this.company,
            name: data.name,
            phone: data.phone,
            jobNum: data.job,
            department: data.department,
            city: data.city
        }
        nyNetwork.net("添加员工", params, data => {
            success();
        })
    }


    net_del_staff(id, success: () => void) {
        nyNetwork.net("删除员工", { id: id }, data => {
            success();
        })
    }

    net_froze_staff(idList, success: () => void) {
        nyNetwork.net("冻结员工", [ ...idList ], data => {
            success();
        })
    }

    net_Unfroze_staff(idList, success: () => void) {
        nyNetwork.net("解冻员工", [ ...idList ], data => {
            success();
        })
    }

    net_reset_pwe(id) {
        nyNetwork.net("重置密码", { id: id }, data => {
        })
    }

    net_edit_staff(obj, success: () => void) {
        nyNetwork.net("编辑员工", obj, data => {
            success();
        })
    }

    net_export_staff(){
        nyNetwork.down("导出员工", {company:this.company} ,'员工列表')
    }

}
export default DZServiceStaff;